﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace ZeroBug.EasyFlow.Communication
{
    public class TCPClientCommState : ICommClientState
    {
        public bool? IsConnected => TcpClient?.Client.Connected;
        public string EndPoint => TcpClient?.Client.RemoteEndPoint.ToString();
        /// <summary>
        /// 客户端
        /// </summary>

        public TcpClient TcpClient { get; set; }
        /// <summary>
        /// 缓存区
        /// </summary>
        public byte[] Buffer { get; set; }
        /// <summary>
        /// 客户端数据流
        /// </summary>
        public NetworkStream NetworkStream { get { return TcpClient?.GetStream(); } }

        public TCPClientCommState()
        {

        }

        public TCPClientCommState(TcpClient tcpClient, byte[] buffer)
            : this()
        {
            if (tcpClient == null)
                throw new ArgumentNullException("TcpClient");
            if (buffer == null)
                throw new ArgumentNullException("Buffer");
            TcpClient = tcpClient;
            Buffer = buffer;
        }
    }
}
